package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.*;

import com.hl.sfzy.service.SysBookingService;
import com.hl.sfzy.service.SysCounselorOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SysBookingController {
    @Autowired
    private SysBookingService sysBookingService;
    @Autowired
private SysCounselorOrderService sysCounselorOrderService;
    @PostMapping("/booking")
    public Result add(@RequestBody SysBooking sysBooking ) {

        int num = sysBookingService.add(sysBooking);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/booking/{id}")
    public Result remove(@PathVariable("id") Integer id) {
        int num = sysBookingService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/booking")
    public Result removeBatch(Integer[] ids) {
        int num = sysBookingService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/booking")
    public Result edit(@RequestBody SysBooking sysBooking) {
        int num = sysBookingService.edit(sysBooking);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/booking/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysBooking sysBooking) {

        Map<String, Object> map = sysBookingService.findPage(pageNum, pageSize, sysBooking);
        return Result.success(map);
    }
    @GetMapping("/booking/{status}")
    public Result findByStatus(@PathVariable("status") Integer status){
        List<SysBooking> byStatus = sysBookingService.findByStatus(status);
        System.out.println(byStatus);
        return Result.success(byStatus);
    }
    @GetMapping("/booking")
    public Result findAll(SysBooking sysBooking){
        List<SysBooking> sysBookings = sysBookingService.find(sysBooking);
        return Result.success(sysBookings);

    }





}
